package org.abacus.platform.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.junit.Test;

public class StringUtil {
	Pattern pattern = Pattern.compile(".*\":\".*\"[,\\}\\]]{1}[^\"]");//

	Pattern p = Pattern.compile("(.*\")([\\,\\}\\]]{1})(.*)");

	@Test
	public void jsonString() {

		System.out.println(s);
		Matcher b = p.matcher(s);
		System.out.println(b.groupCount());
		boolean f = b.matches();
		System.out.println(b.group(1));
		System.out.println(f);
	}

	// String s = "dsfsdfsf\\\":\\\",,,:\\\"}\\\\\",";
	String s = "\\\\\\\"\",";

	@Test
	public void getJsonStringValue() {
		System.out.println(s);
		long start = System.currentTimeMillis();
		int l = 0;
		int len = s.length();
		for (int i = 0; i < len; i++) {
			char c = s.charAt(i);
			if (c == '"') {
				if (i - 1 > 0 && s.charAt(i - 1) != '\\') {
					l = i + 1;
					if (l < len) {
						char end = s.charAt(l);
						if (end == ',' || end == '}' || end == ']') {
							break;
						}
					}
					l = 0;
				}
			}
		}
		long end = System.currentTimeMillis();
		System.out.println(end - start);
		System.out.println(s.substring(0, l - 1).replace("\\\\", "\\").replace("\\\"", "\""));
		System.out.println(l);
		System.out.println(end);
	}
}
